home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3280 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: news.atw.fullfeed.com!usenet
  2. From: sbaierl@sninw.com (Scott J. Baierl)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help on DLLs
  5. Date: Fri, 19 Jan 1996 22:48:00 GMT
  6. Organization: Schneider National, Inc.
  7. Message-ID: <4dp778$o7c@ray.atw.fullfeed.com>
  8. References: <$Eg$ma-0FZ$F078yn@login.dknet.dk>
  9. NNTP-Posting-Host: sbaierl.atw.fullfeed.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. I don't have a small sample handy, but I thought I'd offer advice on
  13. one caveat.  If you need to return a string, allocate it in your
  14. Visual Basic application, pass it ByVal to the .DLL and fill the
  15. buffer in the .DLL.  A Visual Basic string is not a pointer to a
  16. character buffer like in C++.
  17.  
  18. I've seen people actually return a pointer to a character buffer as
  19. from within a .DLL to a VB program as a variant.  They then try to
  20. copy the contents of the (unusable) buffer into a Visual Basic string
  21. using lstrcpy.  The problem is that you can't control the lifetime of
  22. the buffer that was passed to you.  If it was allocated on the stack
  23. in a function call, then it no longer exists.  Your pointer is
  24. invalid.
  25.  
  26. An alternative would be to use the Visual Basic extensions for C/C++
  27. to deal directly with VB string descriptors, but then you can only
  28. call your .DLL function from VB.
  29.  
  30.  
  31. cronberg@login.dknet.dk (Michell Cronberg) wrote:
  32.  
  33. >        I need some help in programming DLL's i C++
  34. >        (Borland for WIN 3.1) to bee used with Visual
  35. >        Basic.
  36.  
  37. >        Does anyone have a short example of a DLL with
  38. >        functions returning an integer and a string.
  39.  
  40. >        Any help would be highly appreciated. Post or mail.
  41.  
  42. >        Thanks in advance.
  43.  
  44. >                Michell Cronberg
  45.  
  46.  
  47.  
  48.